
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 04/15/2016 09:17:47
-- Generated from EDMX file: E:\刘广涛\Yunwei\Yunwei.Web\Test\Model1.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [SmartRestaurant];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Artical]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Artical];
GO
IF OBJECT_ID(N'[dbo].[Category]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Category];
GO
IF OBJECT_ID(N'[dbo].[Chef]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Chef];
GO
IF OBJECT_ID(N'[dbo].[Cuisine]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Cuisine];
GO
IF OBJECT_ID(N'[dbo].[Food]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Food];
GO
IF OBJECT_ID(N'[dbo].[FoodIngredient]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FoodIngredient];
GO
IF OBJECT_ID(N'[dbo].[Ingredient]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Ingredient];
GO
IF OBJECT_ID(N'[dbo].[Order]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Order];
GO
IF OBJECT_ID(N'[dbo].[OrderFoodRel]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderFoodRel];
GO
IF OBJECT_ID(N'[dbo].[Restaurant]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Restaurant];
GO
IF OBJECT_ID(N'[dbo].[RestaurantCuisineRel]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RestaurantCuisineRel];
GO
IF OBJECT_ID(N'[dbo].[RestaurantIngredientRel]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RestaurantIngredientRel];
GO
IF OBJECT_ID(N'[dbo].[Role]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Role];
GO
IF OBJECT_ID(N'[dbo].[Section]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Section];
GO
IF OBJECT_ID(N'[dbo].[Staff]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Staff];
GO
IF OBJECT_ID(N'[dbo].[User]', 'U') IS NOT NULL
    DROP TABLE [dbo].[User];
GO
IF OBJECT_ID(N'[dbo].[UserRoleRel]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserRoleRel];
GO
IF OBJECT_ID(N'[dbo].[Vendor]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Vendor];
GO
IF OBJECT_ID(N'[dbo].[VendorIngredientRel]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VendorIngredientRel];
GO
IF OBJECT_ID(N'[dbo].[Waiter]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Waiter];
GO
IF OBJECT_ID(N'[dbo].[VendorRestaurantRel]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VendorRestaurantRel];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Artical'
CREATE TABLE [dbo].[Artical] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(50)  NOT NULL,
    [SubTitle] nvarchar(100)  NOT NULL,
    [ArticalContent] nvarchar(max)  NOT NULL,
    [Author] nvarchar(50)  NOT NULL,
    [PubTime] datetime  NOT NULL,
    [EditTime] datetime  NOT NULL
);
GO

-- Creating table 'Category'
CREATE TABLE [dbo].[Category] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Avatar] nvarchar(200)  NOT NULL,
    [Description] nvarchar(200)  NOT NULL,
    [Restaurantl_Id] int  NOT NULL
);
GO

-- Creating table 'Chef'
CREATE TABLE [dbo].[Chef] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Avatar] nvarchar(200)  NOT NULL,
    [Birthday] smallint  NOT NULL,
    [Sex] smallint  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Salary] decimal(18,0)  NOT NULL,
    [Cuisine] nvarchar(100)  NOT NULL,
    [Restaurant_Id] int  NOT NULL
);
GO

-- Creating table 'Cuisine'
CREATE TABLE [dbo].[Cuisine] (
    [Id] smallint  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Food'
CREATE TABLE [dbo].[Food] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Cuisine] smallint  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Avatar] nvarchar(200)  NOT NULL,
    [Price] decimal(18,0)  NOT NULL,
    [Discount] decimal(18,0)  NOT NULL,
    [CreateTime] datetime  NOT NULL,
    [Chef_Id] int  NOT NULL,
    [Category_Id] int  NOT NULL,
    [Restaurant_Id] int  NOT NULL
);
GO

-- Creating table 'FoodIngredient'
CREATE TABLE [dbo].[FoodIngredient] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Food_Id] int  NOT NULL,
    [Ingredient_Id] int  NOT NULL
);
GO

-- Creating table 'Ingredient'
CREATE TABLE [dbo].[Ingredient] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Price] decimal(18,0)  NOT NULL,
    [Unit] nvarchar(20)  NOT NULL
);
GO

-- Creating table 'Order'
CREATE TABLE [dbo].[Order] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [OrderNo] nvarchar(max)  NOT NULL,
    [OrderTime] datetime  NOT NULL,
    [TotalPrice] datetime  NOT NULL,
    [Status] smallint  NOT NULL,
    [MealTime] datetime  NOT NULL,
    [RoomPrice] decimal(18,0)  NOT NULL,
    [MealFee] decimal(18,0)  NOT NULL,
    [User_Id] int  NOT NULL,
    [Restaurant_Id] int  NOT NULL
);
GO

-- Creating table 'OrderFoodRel'
CREATE TABLE [dbo].[OrderFoodRel] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Count] nvarchar(max)  NOT NULL,
    [Order_Id] int  NOT NULL,
    [Food_Id] int  NOT NULL
);
GO

-- Creating table 'Restaurant'
CREATE TABLE [dbo].[Restaurant] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Avatar] nvarchar(200)  NOT NULL,
    [Address] nvarchar(50)  NOT NULL,
    [Phone] nvarchar(20)  NOT NULL,
    [X] decimal(18,6)  NOT NULL,
    [Y] decimal(18,6)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Contact] nvarchar(20)  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'RestaurantCuisineRel'
CREATE TABLE [dbo].[RestaurantCuisineRel] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Restaurant_Id] int  NOT NULL,
    [Cuisine_Id] smallint  NOT NULL
);
GO

-- Creating table 'RestaurantIngredientRel'
CREATE TABLE [dbo].[RestaurantIngredientRel] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Cost] decimal(18,0)  NOT NULL,
    [Stock] decimal(18,0)  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Unit] nvarchar(20)  NOT NULL,
    [Vendor] int  NOT NULL
);
GO

-- Creating table 'Role'
CREATE TABLE [dbo].[Role] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Type] int  NOT NULL,
    [Description] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Section'
CREATE TABLE [dbo].[Section] (
    [Id] smallint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(200)  NOT NULL
);
GO

-- Creating table 'Staff'
CREATE TABLE [dbo].[Staff] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Avatar] nvarchar(200)  NOT NULL,
    [Birthday] smallint  NULL,
    [Sex] smallint  NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Salary] decimal(18,2)  NOT NULL,
    [Cuisine] nvarchar(100)  NULL,
    [Restaurant_Id] int  NOT NULL,
    [Job] smallint  NOT NULL
);
GO

-- Creating table 'User'
CREATE TABLE [dbo].[User] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [NickName] nvarchar(50)  NULL,
    [RealName] nvarchar(50)  NULL,
    [Sex] smallint  NOT NULL,
    [Email] nvarchar(50)  NOT NULL,
    [Password] nvarchar(50)  NOT NULL,
    [Phone] nvarchar(20)  NOT NULL,
    [Avatar] nvarchar(200)  NULL,
    [Status] smallint  NOT NULL,
    [RegistTime] datetime  NOT NULL,
    [LoginTime] datetime  NULL,
    [LoginIP] nvarchar(50)  NULL,
    [VIPLevel] smallint  NOT NULL
);
GO

-- Creating table 'UserRoleRel'
CREATE TABLE [dbo].[UserRoleRel] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Role_Id] int  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'Vendor'
CREATE TABLE [dbo].[Vendor] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Address] nvarchar(50)  NOT NULL,
    [Phone] nvarchar(20)  NOT NULL,
    [X] decimal(18,0)  NOT NULL,
    [Y] decimal(18,0)  NOT NULL,
    [Avatar] nvarchar(200)  NOT NULL,
    [User_Id] int  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [Contact] nvarchar(20)  NOT NULL
);
GO

-- Creating table 'VendorIngredientRel'
CREATE TABLE [dbo].[VendorIngredientRel] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Cost] decimal(18,0)  NOT NULL,
    [Price] decimal(18,0)  NOT NULL,
    [Stock] decimal(18,0)  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Unit] nvarchar(20)  NOT NULL,
    [Vendor_Id] int  NOT NULL
);
GO

-- Creating table 'Waiter'
CREATE TABLE [dbo].[Waiter] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Avatar] nvarchar(200)  NOT NULL,
    [Birthday] smallint  NOT NULL,
    [Sex] smallint  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Salary] decimal(18,0)  NOT NULL,
    [Restaurant_Id] int  NOT NULL
);
GO

-- Creating table 'VendorRestaurantRel'
CREATE TABLE [dbo].[VendorRestaurantRel] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Vendor_Id] int  NOT NULL,
    [Restaurant_Id] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ShoppingCart'
CREATE TABLE [dbo].[ShoppingCart] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [User_Id] nvarchar(max)  NOT NULL,
    [Food_Id] nvarchar(max)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Artical'
ALTER TABLE [dbo].[Artical]
ADD CONSTRAINT [PK_Artical]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Category'
ALTER TABLE [dbo].[Category]
ADD CONSTRAINT [PK_Category]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Chef'
ALTER TABLE [dbo].[Chef]
ADD CONSTRAINT [PK_Chef]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Cuisine'
ALTER TABLE [dbo].[Cuisine]
ADD CONSTRAINT [PK_Cuisine]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Food'
ALTER TABLE [dbo].[Food]
ADD CONSTRAINT [PK_Food]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FoodIngredient'
ALTER TABLE [dbo].[FoodIngredient]
ADD CONSTRAINT [PK_FoodIngredient]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Ingredient'
ALTER TABLE [dbo].[Ingredient]
ADD CONSTRAINT [PK_Ingredient]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Order'
ALTER TABLE [dbo].[Order]
ADD CONSTRAINT [PK_Order]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrderFoodRel'
ALTER TABLE [dbo].[OrderFoodRel]
ADD CONSTRAINT [PK_OrderFoodRel]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Restaurant'
ALTER TABLE [dbo].[Restaurant]
ADD CONSTRAINT [PK_Restaurant]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RestaurantCuisineRel'
ALTER TABLE [dbo].[RestaurantCuisineRel]
ADD CONSTRAINT [PK_RestaurantCuisineRel]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RestaurantIngredientRel'
ALTER TABLE [dbo].[RestaurantIngredientRel]
ADD CONSTRAINT [PK_RestaurantIngredientRel]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Role'
ALTER TABLE [dbo].[Role]
ADD CONSTRAINT [PK_Role]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Section'
ALTER TABLE [dbo].[Section]
ADD CONSTRAINT [PK_Section]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Staff'
ALTER TABLE [dbo].[Staff]
ADD CONSTRAINT [PK_Staff]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'User'
ALTER TABLE [dbo].[User]
ADD CONSTRAINT [PK_User]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserRoleRel'
ALTER TABLE [dbo].[UserRoleRel]
ADD CONSTRAINT [PK_UserRoleRel]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Vendor'
ALTER TABLE [dbo].[Vendor]
ADD CONSTRAINT [PK_Vendor]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'VendorIngredientRel'
ALTER TABLE [dbo].[VendorIngredientRel]
ADD CONSTRAINT [PK_VendorIngredientRel]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Waiter'
ALTER TABLE [dbo].[Waiter]
ADD CONSTRAINT [PK_Waiter]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'VendorRestaurantRel'
ALTER TABLE [dbo].[VendorRestaurantRel]
ADD CONSTRAINT [PK_VendorRestaurantRel]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ShoppingCart'
ALTER TABLE [dbo].[ShoppingCart]
ADD CONSTRAINT [PK_ShoppingCart]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------